package com.bhs.sansonglogistics.ui.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.BillBean;
import com.bhs.sansonglogistics.bean.BillingDetails;
import com.bhs.sansonglogistics.utils.DateUtils;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class BillAdapter extends BaseQuickAdapter<BillingDetails.DataDTO.ListDTO, BaseViewHolder> {

    private int type;

    public BillAdapter() {
        super(R.layout.item_bill);
    }

    public BillAdapter(int type) {
        super(R.layout.item_bill);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, BillingDetails.DataDTO.ListDTO item) {
        if (helper.getLayoutPosition() > 0) {
            if (DateUtils.getYearMonth(item.getCreate_time())
                    .equals(DateUtils.getYearMonth(getData().get(helper.getLayoutPosition() - 1).getCreate_time()))) {
                helper.setGone(R.id.tv_date, false);
            }
        }
        helper.setText(R.id.tv_type, MyUtils.billType(item.getType(),item.getNum()));
        helper.setText(R.id.tv_date, DateUtils.getYearMonth(item.getCreate_time()));
        helper.setText(R.id.tv_bill, item.getRemark());
        helper.setText(R.id.tv_money, Double.parseDouble(item.getNum()) > 0 ? String.format("+%s", item.getNum()) : item.getNum());
        helper.setText(R.id.tv_time, DateUtils.getTime2(item.getCreate_time()));
    }
}
